define(['text!/template/${moduleMapperCode}/${(businessCode?uncap_first)!''}/addModal.tpl.html', 'jquery-validation-localization'], function (addModalTpl) {
    'use strict';
    return Marionette.LayoutView.extend({
        id: _.uniqueId("${moduleMapperCode}-${(businessCode?uncap_first)!''}-addModal-"),
        attributes: {
            "title": "新增"
        },
        serializeData: function () {
            var data = this.options.data;

            return data;
        },
        initialize: function () {
            this.template = _.template(addModalTpl);
        },
        onRender: function () {
            _.delay(function (that) {
                that.$el.tooltip(C1.tooltipDefaultOptions);

                that.$('[data-id="form-1"]').validate($.extend({}, C1.validationDefaultOptions, {
                    rules: {
                        name: {
                            required: true,
                            minlength: 4
                        },
                        ${(businessCode?uncap_first)!''}Code: {
                            required: true,
                            minlength: 4
                        }
                    },
                    messages: {
                        name: {
                            required: "请输入名称",
                            minlength: "名称必需由3个字符以上组成"
                        },
                        ${(businessCode?uncap_first)!''}Code: {
                            required: "请输入编号",
                            minlength: "编号必需由3个字符以上组成"
                        }
                    },
                    submitHandler: function (form) {
                        var data = C1.serializeToJson(form);

                        $.ajax({
                            url: $(form).attr('action'),
                            data: data,
                            onSuccess: function (data, textStatus, jqXHR) {
                                C1.modal.alert("提交成功");

                                that.$el.dialog("close");

                                if ($.isFunction(that.options.saveSuccess)) {
                                    that.options.saveSuccess();
                                }
                            }
                        });
                    }
                }));

                var buttons = [
                    {
                        text: that.options.data.i18n_close,
                        click: function () {
                            $(this).dialog("close");
                        }
                    },
                    {
                        text: that.options.data.i18n_submit,
                        "data-toggle": "delayDisabled",
                        click: function () {
                            that.$('[data-id="form-1"]').submit();
                        }
                    }
                ];

                that.$el.dialog({
                    width: "88%",
                    modal: true,
                    close: function (event, ui) {
                        that.triggerMethod("view:removeRegion");
                    },
                    buttons: buttons
                });
            }, 500, this);
        }
    });
});